const path =require('path')
const jsonServer= require('json-server')


const router=require('./router')
const db=require('./db')()

const server =jsonServer.create()


const middlewares=jsonServer.defaults({
  static: path.join(__dirname,'../public')
})

server.use(middlewares)
//req.body   请求体解析中间件
server.use(jsonServer.bodyParser)
//配置路由
router(server)

//jsonServer.router创建一个路由配置
const jsonRouter=jsonServer.router(db)
server.use('/api',jsonRouter)


server.listen(8000,()=>{
  console.log('JSON SERVER  is running at 8000')
})
